<?php
namespace app\wadmin\controller;
// +----------------------------------------------------------------------
// | bbcThink
// +----------------------------------------------------------------------
// | Copyright (c) 2025 http://bbcweb.cn All rights reserved.
// +----------------------------------------------------------------------
// | Licensed ( http://www.apache.org/licenses/LICENSE-2.0 )
// +----------------------------------------------------------------------
// | Author: bbcweb <22745529@qq.com>
// +----------------------------------------------------------------------
use app\BaseController;
use think\facade\Db;
use think\facade\View;

/**
 * log管理
 */
class Log extends BaseController
{
    protected $table='log';
    public function initialize()
    {
        parent::initialize();
    }
	public function Index()
	{
	    $p=input();
        $where=array();
        $datalist = Db::name($this->table)->where($where)->order('id desc')->paginate(['listrows'=>20,'query'=>$p]);
        $list=array();
        foreach($datalist->items() as $v)
        {
            $v['shop_name']='';
            $v['admin_name']='';
            if(!empty($v['add_time']))
            {
                $v['add_time']=formatDate($v['add_time']);
            }
           
            if(!empty($v['user_id']))
            {
                $user=Db::name('admin')->where('id',$v['user_id'])->find();
                if(!empty($user))
                {
                    $v['admin_name']=$user['name'];
                }
            }
            $v['sn']=empty($v['sn'])?'':$v['sn'];
            $v['memo']=empty($v['memo'])?'':$v['memo'];
            $list[]=$v;
        }
        $page = $datalist->render();
        View::assign('data_list',$list);
        View::assign('page',$page);
        $auth=cache("log_auth");
        View::assign('auth',$auth);
        return View::fetch();
	}
	public function auth()
	{
	    $p=input();
	    if($p['password']=='log123456')
	    {
	        cache('log_auth',1,60);
	        return jsonRes(1);
	    }
	    return jsonRes(0);
	}
	
	public function remove()
	{
        $p = input();
        if(empty($p['id']))
        {
            Db::name($this->table)->delete(true);
        }
        else
        {
            Db::name($this->table)->where(['id'=>$p['id']])->delete();
        }
        return jsonRes(1);
	}
}
?>